Skip to content

Enable SwiftLint rule: flatmap_over_map_reduce#25529

Merged
mokagio merged 1 commit intotrunkfrom
mokagio/swiftlint-flatmap-over-map-reduce
May 7, 2026
Merged

Enable SwiftLint rule: flatmap_over_map_reduce#25529
mokagio merged 1 commit intotrunkfrom
mokagio/swiftlint-flatmap-over-map-reduce

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 5, 2026

Summary

Enables SwiftLint's flatmap_over_map_reduce rule.

The rule prefers flatMap { ... } over map { ... }.reduce([], +) for flattening nested arrays — this avoids materialising an intermediate array of arrays.

  • See commit message for the violation count and any rewrites.
  • The change is type-preserving — local build deferred to CI.

Part of the Orchard SwiftLint rollout campaign.

Test plan

  • CI build is green.
  • swiftlint lint --strict --no-cache is clean against the rule.

🤖 Generated with Claude Code

@mokagio mokagio self-assigned this May 5, 2026
@mokagio mokagio added this to the 26.9 milestone May 5, 2026
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 5, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32157
VersionPR #25529
Bundle IDorg.wordpress.alpha
Commit63df54e
Installation URL61ug1gm5cruu8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 5, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number32157
VersionPR #25529
Bundle IDcom.jetpack.alpha
Commit63df54e
Installation URL1t7p91ma5qs0o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@mokagio mokagio marked this pull request as ready for review May 6, 2026 01:29
Copilot AI review requested due to automatic review settings May 6, 2026 01:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables SwiftLint’s flatmap_over_map_reduce rule and updates the one in-repo occurrence to match the preferred flattening pattern, avoiding the intermediate array-of-arrays allocation.

Changes:

  • Enabled the flatmap_over_map_reduce rule in .swiftlint.yml.
  • Replaced map { ... }.reduce([], +) with flatMap { ... } in GutenbergFilesAppMediaSource.getDocumentTypes(...).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
WordPress/Classes/ViewRelated/Gutenberg/Utils/GutenbergFilesAppMediaSource.swift Updates array-flattening implementation to use flatMap per new SwiftLint rule.
.swiftlint.yml Adds flatmap_over_map_reduce to the opt-in only_rules list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mokagio mokagio enabled auto-merge May 7, 2026 00:38
Adds the rule to `only_rules`. The rule prefers `flatMap { ... }`
over `map { ... }.reduce([], +)` for flattening nested arrays —
this avoids materialising an intermediate array of arrays.

Part of the Orchard SwiftLint rollout campaign.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.7 <noreply@anthropic.com>
@mokagio mokagio force-pushed the mokagio/swiftlint-flatmap-over-map-reduce branch from 21dcf30 to 63df54e Compare May 7, 2026 00:39
@mokagio mokagio added this pull request to the merge queue May 7, 2026
Merged via the queue into trunk with commit 6a8842f May 7, 2026
24 checks passed
@mokagio mokagio deleted the mokagio/swiftlint-flatmap-over-map-reduce branch May 7, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants